package com.youthburin.base.util;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;

public class DwzResponse implements Serializable {
	private static final long serialVersionUID = 1L;
	private String statusCode = "";
	private String message = "";
	private String navTabId = "";// navTabId可以把那个navTab标记为reloadFlag=1,下次切换到那个navTab时会重新载入内容
	private String rel = "";
	private String callbackType = "";// 为是closeCurrent就会关闭当前tab,为forward时需要forwardUrl值
	private String forwardUrl = "";

	public DwzResponse(DwzResponseCode statusCode, String message, CallbackType callbackType, String forwardUrl,
			String navTabId) {
		super();
		if (statusCode != null)
			this.statusCode = statusCode.getValue();
		if (this.message != null)
			this.message = message;
		if (callbackType != null)
			this.callbackType = callbackType.getValue();
		if (this.forwardUrl != null)
			this.forwardUrl = forwardUrl;
		if (this.navTabId != null)
			this.navTabId = navTabId;
	}

	public String getStatusCode() {
		return statusCode;
	}

	public void setStatusCode(String statusCode) {
		this.statusCode = statusCode;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getNavTabId() {
		return navTabId;
	}

	public void setNavTabId(String navTabId) {
		this.navTabId = navTabId;
	}

	public String getRel() {
		return rel;
	}

	public void setRel(String rel) {
		this.rel = rel;
	}

	public String getCallbackType() {
		return callbackType;
	}

	public void setCallbackType(String callbackType) {
		this.callbackType = callbackType;
	}

	public String getForwardUrl() {
		return forwardUrl;
	}

	public void setForwardUrl(String forwardUrl) {
		this.forwardUrl = forwardUrl;
	}

	enum CallbackType {
		CLOSE("closeCurrent"), FORWARD("forward");
		private final String value;

		private CallbackType(String value) {
			this.value = value;
		}

		public String getValue() {
			return this.value;
		}

		public static String toCode(CallbackType theEnum) {
			return theEnum.getValue();
		}

		public static CallbackType fromCode(String code) {
			CallbackType[] theEnums = CallbackType.values();
			for (CallbackType theEnum : theEnums) {
				if (StringUtils.equals(theEnum.value, code))
					return theEnum;
			}
			return null;
		}
	}

	enum DwzResponseCode {
		/** 操作成功 */
		SUCCESS("200"),
		/** 操作失败 */
		FAIL("300"),
		/** 会话超时 */
		TIMEOUT("301");
		private final String value;

		private DwzResponseCode(String value) {
			this.value = value;
		}

		public String getValue() {
			return this.value;
		}

		public static String toCode(DwzResponseCode theEnum) {
			return theEnum.getValue();
		}

		public static DwzResponseCode fromCode(String code) {
			DwzResponseCode[] theEnums = DwzResponseCode.values();
			for (DwzResponseCode theEnum : theEnums) {
				if (StringUtils.equals(theEnum.value, code))
					return theEnum;
			}
			return null;
		}
	}
}
